#ifndef _GAME_PLAYER_H_
#define _GAME_PLAYER_H_

#include "SDL2/SDL.h"

/* states a player can have
 * depending on them, movement, casting
 * or other actions may be disabled
 */
enum PLAYER_STATES {
	IDLE,
	JUMP,
	FALL,
	CAST,
	ATTACK,
	DROWN,
};

/* game player
 * the player can:
 ** move left/right
 ** jump/fall (gravity)
 ** activate skill (not implemented)
 ** attack (not implemented)
 */
struct game_player {

	// player's texture and rect
	SDL_Texture *tex;
	SDL_Rect tex_rect;
	SDL_Rect rect;

	// size of player
	int tex_size;

	// animation and states
	enum PLAYER_STATES state;
	int anim_count;
	enum {LOOKING_LEFT = -1, LOOKING_RIGHT = 1} looking_side;

	// left/right movement
	enum {MOVE_LEFT = -1, MOVE_NONE, MOVE_RIGHT} move;
	float speed_max;
	float velocity_x;
	float velocity_y;

	/* reference to map
	 * needed when casting skills that affect the map,
	 * or walking on it, platform_id defines the id of the platform
	 * the player walks on
	 */
	struct game_map *map;
	int platform_id;

	/* reference to players
	 * the players on the map so that this player can interact with them
	 * or move around them
	 */
	struct game_player *players;

	/* ai players have a target they keep following
	 */
	int map_target;

	// casting skill variables
	int casting_cooldown;

	// player level
	int level;

}; // game_player

/* basic interaction
 */
void game_player_init(struct game_player *, struct game_map *);
void game_player_update(struct game_player*);
void game_player_draw(struct game_player*);

/* movement commands
 * any movement will remain active until cancelled
 */
void game_player_moveleft(struct game_player *);
void game_player_moveright(struct game_player *);
void game_player_movestop(struct game_player *);

// jumping is one-off
void game_player_jump(struct game_player *);

// player's special skill
void game_player_useskill(struct game_player *);

// player's attack
void game_player_attack(struct game_player *);

// ai
void game_player_ai(struct game_player *);

// use to bump a player away, from given direction
void game_player_bump(struct game_player *, struct game_player *p);

// collision data
int game_player_left(struct game_player *);
int game_player_top(struct game_player *);
int game_player_right(struct game_player *);
int game_player_bottom(struct game_player *);
int game_player_centerx(struct game_player *);
int game_player_centery(struct game_player *);

void game_player_offset(struct game_player *, int, int);

// getters
int game_player_get_state(struct game_player *);

#endif
